<template>
	<view class="loginfoor">
		<view class="loginfoor_top">
			<view class="loginfoor_top_user">
				<view class="">
					<img style='width: 150px; height: 150px; border-radius: 50%;' :src="userlist.imglog" alt="">
				</view>
				<view style="font-size: 18px; margin-top: 10px;">
					{{userlist.name}}
				</view>
			</view>
		</view>
		<view class="loginfoor_main">
			<view style="font-size: 18px; margin: 10px 0 20px;">
				申请获得一下权限
			</view>
			<view style="font-size: 17px; color: #636363;">
				· 获得您的公开信息（昵称 ，头像等）
			</view>
		</view>
		<view class="loginfoor_toor">
			<button style="background-color: #3c9cff; color: #fff;" @click="loginfoor()">授 权 登 录</button>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userlist: {
					name: '商 城 登 录',
					imglog: '../../static/a.jpg'
				},
				datalist: {
					code: '',
					userInfo: ''
				}
			}
		},
		methods: {


			loginfoor() {
				let data = 'sssd'
				uni.setStorage({
					key: 'userdata',
					data: data,
					success: function() {
						console.log('success');
					}
				})

				// this.$http.myCache('userdata', data, 3600 * 24)



				// this.$http.myCache('userdata')

				this.shouquan = false
				uni.getUserProfile({
					lang: 'zh_CN',
					desc: '登录',
					success: infoRes => {
						let this_ = this
						console.log(infoRes.userInfo);
						this.userlist.name = infoRes.userInfo.nickName
						this.userlist.imglog = infoRes.userInfo.avatarUrl
						this.datalist.userInfo = JSON.stringify(infoRes.userInfo)
						uni.login({
							success(res) {
								this_.datalist.code = res.code
								console.log(this_.datalist);
								this_.$http.postlogin(this_.datalist).then(res => {
									console.log(res);
									this_.$http.myCache('userdata', res.data, 86400)
									if(res.code == '1'){
										uni.reLaunch({
											url: '../my/my'
										});
									}


									// uni.setStorage({
									// 	key: 'userdata',
									// 	data: res.data,
									// 	success: function() {
									// 		console.log('success');
									// 	}
									// })
								})
							}
						})



					},
					fail(res) {
						uni.showToast({
							title: '登录授权失败',
							icon: 'none',
						})
					}
				});
			},


		}
	}
</script>

<style>
	.loginfoor {
		padding: 20px 40px 0 40px;
		height: 100%;
		background-color: #f7f7f7;
	}

	.loginfoor_top {
		display: flex;
		justify-content: center;
		padding-bottom: 50px;
		border-bottom: 1px solid #c5c5c5;
	}

	.loginfoor_top_user {
		text-align: center;
		display: flex;
		justify-content: center;
		flex-direction: column;
	}

	.loginfoor_main {
		margin: 30px 0 30px 0;
	}
</style>
